<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>商品分类</title>
    <link rel="stylesheet " href="__PUBLIC__/css/bootstrap.min.css ">
    <link rel="stylesheet " href="__PUBLIC__/h-ui.admin/css/category.css ">
    <script src="__PUBLIC__/js/jquery.min.js "></script>
    <script src="__PUBLIC__/js/bootstrap.min.js "></script>
    <script src="__ROOT__/lib/layer/2.4/layer.js "></script>
</head>

<body>
    <div class="breadcrumb-wrap container-fluid">
        <ol class="breadcrumb pull-left">
            <li><a href="#">后台管理</a></li>
            <li class="active">商品分类</li>
        </ol>
        <a href="{:U('Goods/add_category')}" class="pull-right add-category">添加分类</a>
    </div>
    <table class="table table-hover table-bordered table-alex">
        <tr style="background-color: #E5F6FE" align="center">
            <td>分类ID</td>
            <td>分类名称</td>
            <td>分类描述</td>
            <td>上级分类</td>
            <td>排序</td>
            <td>操作</td>
        </tr>
        <foreach name="data" item="val">
            <tr align="center">
                <td>{$val.cat_id}</td>
                <td>{$val.level|str_repeat='&emsp;',###*3}{$val.cat_name}</td>
                <td>{$val.cat_desc}</td>
                <td>
                    <if condition="$val.parent_name == null">顶级分类
                        <else/>{$val.parent_name}</if>
                </td>
                <td>{$val.level|str_repeat='&emsp;',###*4}
                    <input type="text" name="sort[1]" value="{$val.sort_order}" sid="{$val.cat_id}" class="sort-input">
                </td>
                <td><a href="{:U('edit_category',array('id'=>$val['cat_id']))}">编辑</a> | <a href="javascript:;" data-id={$val.cat_id} class="category-del">删除</a></td>
            </tr>
        </foreach>
    </table>
    <div class="container-fluid" align="center">
      <ul class="pagination">
        {$show}
    </ul>  
    </div>
     
</body>

</html>
<script type="text/javascript">
$(function() {
	// 删除商品的提示
    $(".category-del").on('click', function() {
        var id = $(this).attr('data-id');
        console.log(id);
        layer.confirm('您真的要删除吗?', {
            btn: ['删除', '取消'] //按钮
        }, function() {
            $.get('__CONTROLLER__/del_category/id/' + id, function(data) {
                if (data == 1) {
                    layer.msg("删除成功", { time: 1000 }, function() {
                        location.reload();
                    });
                } else {
                    layer.msg("删除失败");
                }
            });
        }, function() {
        });
    })
    // 修改排序
    $(".sort-input").on('blur', function() {
        // 获取修改的要修改的id
        var sid = $(this).attr('sid');
        // 获取要修改的值
        var sortVal = $(this).val();
        console.log(sid);
        console.log(sortVal);
        // ajax刷新
        $.ajax({
            // 显示三步走
            // 去和谁交互
            url: "{:U('Admin/Goods/navSort')}",
            // 怎么交互get或者post
            type: 'post',
            // 把什么东西给他
            data: { "sid": sid, "sortVal": sortVal },
            // 以什么格式传输
            dataType: 'json',
            // 如果成功怎么样
            success: function(data) {
                if (data.status == -1) {
                    alert(data.info);
                } else if (data.status == 1) {
                    location.reload();
                } else {
                    alert(data.info);
                }
            }
        })

    })
});
</script>